//
//  CETestCaseCache.m
//  CELog_Example
//
//  Created by maoerduo on 2021/3/1.
//  Copyright © 2021 maoerduo. All rights reserved.
//

#import "CETestCaseCache.h"

@interface CETestCaseCache()

@property (nonatomic, strong) NSUserDefaults * cacheStore;

@end

@implementation CETestCaseCache

+ (instancetype)shared {
    
    static CETestCaseCache * cache = nil;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        cache = [[self alloc] init];
    });
    
    return cache;
    
}

- (instancetype)init {
    
    self = [super init];
    
    if (self) {
        self.cacheStore = [[NSUserDefaults alloc] initWithSuiteName:@"com.library.cetester"];
    }
    
    return self;
    
}

- (void)save:(NSDictionary *)strategy forTestCase:(id<CETestCase>)testCase {
    [self.cacheStore setObject:strategy forKey:testCase.identifier];
    [self.cacheStore synchronize];
}

- (NSDictionary *)loadForTestCase:(id<CETestCase>)testCase {
    return [self.cacheStore objectForKey:testCase.identifier];
}

@end
